package com.ruoyi.project.hcy.administrations.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.hcy.administrations.domain.Train;
import com.ruoyi.project.hcy.administrations.service.ITrainService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName ApproveController
 * @Author 金刚芭比
 * @Date 2020/9/17 10:55
 * @Version 1.0
 */
@Controller
@RequestMapping("/hcy/train")
public class TrainController extends BaseController {

    private String prefix="hcy/administrations";

    @Autowired
    private ITrainService trainService;

    @GetMapping
    public String toTrain(){
        return prefix + "/train";
    }

    @RequiresPermissions("hcy:train:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo TrainList(){
        startPage();
        List<Train> list = trainService.selectTrainAll("待审批..");
        return getDataTable(list);
    }

    //添加申请页面
    @GetMapping("/add")
    public String toaddTrain(){
        return prefix + "/addtrain";
    }
    @RequiresPermissions("hcy:train:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addTrain(@Validated Train train){
        return toAjax(trainService.insertTrain(train));
    }

}
